import Vue from 'vue'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)

function loadLocaleMessages () {
  const locales = require.context('../common/locales', true, /[A-Za-z0-9-_,\s]+\.json/i)
  const messages = {
      'zh-CN': require('../common/locales/zh.json'),   // 中文语言包
      'en-US': require('../common/locales/en.json')    // 英文语言包
  }
  locales.keys().forEach(key => {
    const matched = key.match(/([A-Za-z0-9-_]+)\./i)
    if (matched && matched.length > 1) {
      const locale = matched[1]
      messages[locale] = locales(key)
    }
  })
  return messages
}

export default new VueI18n({
    locale:'zh',
    fallbackLocale:'zh',
    //locale: process.env.VUE_APP_I18N_LOCALE || 'zh',
   // fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'zh',
    messages: loadLocaleMessages()
})
